import { Controller, Post, Body, Delete } from '@nestjs/common';
import { TokenService } from './token.service';

@Controller('token')
export class TokenController {
  constructor(private readonly tokenService: TokenService) {}

  // 更新/生成token
  @Post('update')
  async updateToken(@Body('userId') userId: string) {
    const token = await this.tokenService.updateToken(userId);
    return { token };
  }

  // 删除token
  @Delete('delete')
  async deleteToken(@Body('userId') userId: string) {
    await this.tokenService.deleteToken(userId);
    return { msg: '删除成功' };
  }

  // 验证token
  @Post('validate')
  async validateToken(@Body('token') token: string) {
    const valid = await this.tokenService.validateToken(token);
    return { valid };
  }
} 